package com.screen.screendisplay.service.impl.electric;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.screen.screendisplay.entity.electric.ElectricProdoperCoalConsumeLr;
import com.screen.screendisplay.mapper.electric.ElectricProdoperCoalConsumeLrMapper;
import com.screen.screendisplay.service.electric.ElectricProdoperCoalConsumeLrService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 火电生产实时负荷表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class ElectricProdoperCoalConsumeLrServiceImpl extends ServiceImpl<ElectricProdoperCoalConsumeLrMapper, ElectricProdoperCoalConsumeLr> implements ElectricProdoperCoalConsumeLrService {

    /**
     * 火电生产实时负荷表
     * @return
     */
    @Override
    public List<ElectricProdoperCoalConsumeLr> prodoperCoalConsume() {
        // 获取今天的开始和结束时间
        LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT);
        LocalDateTime todayEnd = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        
        // 获取昨天的开始和结束时间
//        LocalDateTime yesterdayStart = todayStart.minusDays(1);
//        LocalDateTime yesterdayEnd = todayEnd.minusDays(1);
        LocalDateTime yesterdayStart = LocalDateTime.of(2024, 1, 4, 0, 0);
        LocalDateTime yesterdayEnd = LocalDateTime.of(2024, 1, 4, 23, 59, 59);
        
        // 查询今日和昨日的负荷数据
        List<ElectricProdoperCoalConsumeLr> result = new ArrayList<>();
        
        // 查询今日数据
        List<ElectricProdoperCoalConsumeLr> todayData = this.lambdaQuery()
                .ge(ElectricProdoperCoalConsumeLr::getRecordDate, todayStart)
                .le(ElectricProdoperCoalConsumeLr::getRecordDate, todayEnd)
                .orderByAsc(ElectricProdoperCoalConsumeLr::getHour)
                .list();
        
        // 查询昨日数据
        List<ElectricProdoperCoalConsumeLr> yesterdayData = this.lambdaQuery()
                .ge(ElectricProdoperCoalConsumeLr::getRecordDate, yesterdayStart)
                .le(ElectricProdoperCoalConsumeLr::getRecordDate, yesterdayEnd)
                .orderByAsc(ElectricProdoperCoalConsumeLr::getHour)
                .list();
        
        // 将今日和昨日数据合并到结果中
        result.addAll(todayData);
        result.addAll(yesterdayData);
        
        return result;
    }
}